import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
import {routes} from './routes'
import NProgess from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(VueRouter)
NProgess.inc(0.2)
NProgess.configure({easing:"ease",speed:200,showSpinner:false})

const router = new VueRouter({
  routes,
  mode:'history'
})

router.beforeEach((to,from,next) => {
  NProgess.start()
  if(to.name != "login" && !store.state.token) {
    next('/login')
  }
  else next()
})
router.afterEach(()=>{
  NProgess.done()
})

export default router
